package practice3;

import javax.sound.midi.Soundbank;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class P8700 {

    public static boolean isOk(String outside,String middle,String inside){

        for(int i=0;i<4;i++){
            Map<String,Integer> map = new HashMap<>();
            map.put("G",0);
            map.put("R",0);
            map.put("Y",0);
            char a = inside.charAt(i);
            char b1 = middle.charAt(i);
            char b2 = middle.charAt(i + 4);
            char c1 = outside.charAt(i);
            char c2 = outside.charAt(i + 4);
            char c3 = outside.charAt(i + 8);
            map.put(a+"",map.get(a+"")+1);
            map.put(b1+"",map.get(b1+"")+1);
            map.put(b2+"",map.get(b2+"")+1);
            map.put(c1+"",map.get(c1+"")+1);
            map.put(c2+"",map.get(c2+"")+1);
            map.put(c3+"",map.get(c3+"")+1);
            if(map.get("G")!=3 || map.get("R")!=2 || map.get("Y")!=1){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        for(int i=0;i<n;i++){
            String outside = sc.next();
            String middle = sc.next();
            String inside = sc.next();
            boolean flag = isOk(outside, middle, inside);
            if(flag){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}
